package view
{
	import flash.display.GradientType;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import model.Utils;
	
	/**
	 * ...
	 * @author Yang Wang
	 */
	public class Square extends Sprite
	{
		
		import model.Constants;
		
		private var m_color:uint;
		private var m_borderWidth:uint;
		private var m_borderColor:uint;
		
		public function Square(color:int = -1, borderWidth:uint = 2, borderColor:uint = 0x333333)
		{
			if (color == -1)
			{
				color = Utils.randomColor();
				color = 0xff0000;
			}
			m_color = color;
			m_borderWidth = borderWidth;
			m_borderColor = borderColor;
			
			this.draw();
		}
		
		public function draw():void
		{
			this.graphics.beginFill(m_borderColor, 1);
			this.graphics.drawRect(0, 0, Constants.SQUARE_DIMENSION, Constants.SQUARE_DIMENSION);
			this.graphics.endFill();
			
			graphics.beginGradientFill(GradientType.RADIAL, new Array(m_color, 0xffffff), [1, 1], [0, 127]);
			graphics.drawRect(m_borderWidth, m_borderWidth, Constants.SQUARE_DIMENSION - m_borderWidth * 2, Constants.SQUARE_DIMENSION - m_borderWidth * 2);
			graphics.endFill();
		}
		
		public function clone():Square
		{
			return new Square(m_color, m_borderWidth, m_borderColor);
		}
	}

}